package com.example.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Binder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Bean> data =new ArrayList<>();
    private static TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        for (int i=0;i<100;i++){
            Bean bean =new Bean();
            bean.setName("享学"+i);
            data.add(bean);
            Log.e("leo","position"+i);
            System.out.println("i==>"+i);
        }
        ListView listView=findViewById(R.id.lv);
        listView.setAdapter(new MyAdapter(data,this));
        //创建ArrayAdapter
       // ArrayAdapter<String> adapter = new ArrayAdapter<String(this,android.R.layout.simple_expandable_list_item_1,data);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               // Log.e("无敌","position"+parent.get);
                /*switch(0){
                    case 0: break;
                }*/
                Log.e("无敌","position"+view.getId()+id);
                textView=(TextView)view.findViewById(R.id.text1);
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Log.e("无敌","笑笑生position"+position+textView.getText().toString());
                    }
                });
                Log.e("无敌","position"+position+textView.getText().toString());
            }
        });
        //listView.setSelection(0)可以直接跳到顶部
        //listView.smoothScrollToPosition(0)可以平滑滚动到顶部
        //当传入打他数据不是同一个array时需要调用myAdapter.notifyDataSetChanged();进行数据刷新
    }
}